package com.mmg.spzx.common.exception;

import com.mmg.spzx.model.vo.common.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理类
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return Result.build(null, 201, e.getMessage());
    }

    @ExceptionHandler(value = MmgException.class)     // 处理自定义异常
    @ResponseBody
    public Result error(MmgException exception) {
        exception.printStackTrace();
        return Result.build(null, exception.getCode(), exception.getMessage());
    }
}
